package top.whysu.gps.controller.system;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.whysu.gps.dto.generate.ResponseDTO;
import top.whysu.gps.dto.page.PagenationDataDTO;
import top.whysu.gps.dto.system.RoleQueryDTO;
import top.whysu.gps.po.system.RolePO;
import top.whysu.gps.service.system.RoleService;
import top.whysu.gps.utils.ResponseUtil;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 系统角色控制类
 */
@Controller
@RequestMapping("/role")
public class RoleController {

    @Resource
    private RoleService roleService;

    /**
     * 角色管理界面
     */
    @GetMapping("/roleManagement")
    public String roleManager() {
        return "role/roleManagement";
    }

    /**
     * 角色管理-列表查询
     *
     * @return
     */
    @RequestMapping("/getPage")
    @ResponseBody
    public ResponseDTO<PagenationDataDTO<RolePO>> getPage(@RequestBody final RoleQueryDTO queryDTO) {
        PagenationDataDTO<RolePO> rolePage = roleService.selectPageRole(queryDTO);
        return ResponseUtil.getSuccessResponse(rolePage);
    }

    /**
     * 角色下拉框查询
     */
    @RequestMapping("/getSelectList")
    @ResponseBody
    public ResponseDTO<List<Map<String, Object>>> getSelectList() {
        List<Map<String, Object>> resultList = roleService.selectListRole();
        return ResponseUtil.getSuccessResponse(resultList);
    }
}
